package com.sun.designpatternsdemo.proxy.bean

import android.util.Log

/**
 * 版权：xx公司 版权所有
 * @author sun
 * 版本：1.0
 * 创建日期：2021/7/1 14:15
 * 描述：实体类
 *创建一个接口
 */
interface Image {
    fun display()
}

class ProxyImage(var fileName: String) : Image {
    private var realImage: RealImage? = null
    override fun display() {
        if (realImage == null) {
            realImage = RealImage(fileName)
        }
        realImage?.display()
    }

}

class RealImage(var fileName: String) : Image {

    init {
        loadFromDisk(fileName)
    }

    private fun loadFromDisk(fileName: String) {
        Log.e("RealImage", "loading $fileName")
    }

    override fun display() {
        Log.e("RealImage", "Displaying $fileName")
    }
}